#ifndef WORLDOBJECT_H
#define WORLDOBJECT_H

#include <QRect>
#include <QString>
#include "gameconstants.h"
#include "gamewindow.h"
class ModelObserver;
class NetworkObserver;

class WorldObject
{
protected:
    QRect rect;
    int objId;
    int speed;
    bool isMovable; // true if the object is moving (updatePosition will only be called if isMovable is true)
    bool isHitable; // true if the object can be hit
    bool destroyLater; // true when object has to be deleted (b/c it is hit by coconut or b/c went out of the window
    Type type;

    int imageIndex;
    QString image;

    static int nextId;

    ModelObserver* mObs;

public:
    WorldObject();
    WorldObject(int x, int y, int width, int height);

    void attachObserver(ModelObserver* m)
    {
        mObs = m;
    }

    // sets nextId back to 0
    static void resetId() { nextId = 0; }

    // moves the object
    virtual void updatePosition() { }

    // sets the next Image
    virtual void nextImage() { }

    int getId() { return objId; }
    int getSpeed() { return speed; }
    QRect& getRect() { return rect; }
    bool getIsMovable() { return isMovable; }
    bool getIsHitable() { return isHitable; }
    bool getDestroyLater() { return destroyLater; }
    Type getType() { return type; }
    int getImageIndex() { return imageIndex; }
    QString getImage() { return image; }

    int getLeft() { return rect.x(); }
    int getRight() { return rect.x() + rect.width(); }
    int getTop() { return rect.y(); }
    int getBottom() { return rect.y() + rect.height(); }

    void setX(int x) { rect.setX(x); }
    void setY(int y) { rect.setY(y); }
    void setSpeed(int s) { speed = s; }
    void setIsMovable(bool b) { isMovable = b; }
    void setIsHitable(bool h) { isHitable = h; }
    void setDestroyLater(bool d) { destroyLater = d; }
    void setImageIndex(int i) { imageIndex = i; }
    void setImage(QString img) { image = img; }

    virtual ~WorldObject() { }
};

#endif // WORLDOBJECT_H
